package com.guoguo.api;

import com.alibaba.fastjson.JSONObject;
import com.guoguo.base.BaseController;
import com.guoguo.entity.SysVersion;
import com.guoguo.enums.SysEnum;
import com.guoguo.service.ISysVersionService;
import com.guoguo.service.IUsersService;
import com.guoguo.utils.StringUtils;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/15 0015.
 */

     /*
                           _ooOoo_
                          o8888888o
                          88" . "88
                          (| -_- |)
                          O\  =  /O
                       ____/`---'\____
                     .'  \\|     |//  `.
                    /  \\|||  :  |||//  \
                   /  _||||| -:- |||||-  \
                   |   | \\\  -  /// |   |
                   | \_|  ''\---/''  |   |
                   \  .-\__  `-`  ___/-. /
                 ___`. .'  /--.--\  `. . __
              ."" '<  `.___\_<|>_/___.'  >'"".
             | | :  `- \`.;`\ _ /`;.`/ - ` : | |
             \  \ `-.   \_ __\ /__ _/   .-` /  /
        ======`-.____`-.___\_____/___.-`____.-'======
                           `=---='
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                 佛祖保佑       永无BUG
        */
@RestController
@RequestMapping("/api/sys")
public class SysController extends BaseController {
    private Logger log = LoggerFactory.getLogger(AppLoginController.class);
    @Resource
    private ISysVersionService iSysVersionService;

    @RequestMapping(value = "/version", method = RequestMethod.POST)
    public JSONObject version(String versionNo, int phoneType) {
        Map<String, String> data = new HashedMap();
        SysVersion sysVersion = iSysVersionService.findNewVersion(phoneType);
        if (sysVersion != null) {
            int status = StringUtils.compareVersion(versionNo, sysVersion.getVersionNo());
            if (status < 0) {
                data.put("newVersionNo", sysVersion.getVersionNo());
                data.put("url", sysVersion.getUrl());
            }
            return returnResult(SysEnum.SYS_VERSION_SUCCESS.getId(), data, SysEnum.SYS_VERSION_MESSAGE_UPDATE.getValue());
        } else {
            return returnResult(SysEnum.SYS_VERSION_SUCCESS.getId(), data, SysEnum.SYS_VERSION_MESSAGE_NOT.getValue());
        }

    }
}
